' //***************************************************************************
' // ***** Script Header *****
' //
' // Solution:  Solution Accelerator for Business Desktop Deployment
' // File:      DeployWiz_Validation.vbs
' //
' // Purpose:   Validate wizard panes used in the deployment wizard
' //
' // Usage:     (used by DeployWiz_Definition_ENU.xml)
' //
' // Microsoft Solution Version:  3.0.139
' // Microsoft Script Version:    3.0.139
' // Customer Build Version:      1.0.0
' // Customer Script Version:     1.0.0
' //
' // Microsoft History:
' // 3.0.53  MTN      08/04/2006  Added comment block, product key logic
' // 3.0.78  MTN      10/10/2006  Removed "side effect" SelectImage logic
' // 3.0.103 MTN      11/02/2006  Added ValidateBDE functions
' // 3.0.112 MTN      11/19/2006  Fixed issues in ValidateDeployRoot
' // 3.0.121 MTN      11/29/2006  Fixed PIN validation
' // 3.0.122 MTN      11/29/2006  Display error when ValidateConnection fails
' // 3.0.134 MTN      01/02/2007  Validate credentials for last wizard pane and
' //                              domain join.
' // 3.0.139 MTN      01/12/2007  Don't validate domain credentials for workgroups
' // 4.0.249 TJ       07/25/2007  Added Validation for Image Capture location.
' // 4.0.259 TPM      08/06/2007  Removed OS validation in the TS validation to
' //				  accomodate non-OS install task sequences
' // 4.0.302 TPM      08/08/2007  Modified ValidateTSList to check if TS template is ClientReplace
' // 4.0.305 TJ       08/14/2007  Fixed Validation for Image Capture.
' // Customer History:
' //
' // ***** End Header *****
' //***************************************************************************

Option Explicit


'''''''''''''''''''''''''''''''''''''
'  Validate DeployRoot and Credentials
'


Function ChangeServerFromSite

	Dim oItem
	dim UpperBound
	dim oServer
	dim Index

	dim oServerList

	if oXMLSiteData is nothing then
		exit function
	end if 

	for each oItem in oXMLSiteData.selectNodes("//servers/server")   
		if SiteList.value = oItem.selectSingleNode("serverid").text then   
      
			set oServerList = oItem.selectNodes("(server1|server2|server3|server4|server5|server6|server7|server8|server9|server|UNCPath)")   
      
			' Get the Weighted Value UpperBound
			UpperBound = 0
			for each oServer in oServerList
				if oServer.Attributes.getQualifiedItem("weight","") is nothing then
					 UpperBound = UpperBound + 1
				else 
					 UpperBound = UpperBound + cint(oServer.Attributes.getQualifiedItem("weight","").Value)
				end if
			next
      
			randomize
			Index = int(rnd * UpperBound + 1)
   
			' Pick a random server entry based on Weighted Value.
			UpperBound = 0
			for each oServer in oServerList	
				 if oServer.Attributes.getQualifiedItem("weight","") is nothing then
					  UpperBound = UpperBound + 1			
				 else 
					  UpperBound = UpperBound + cint(oServer.Attributes.getQualifiedItem("weight","").Value)		
				 end if
					
				 if Index <= UpperBound then
					  DeployRoot.value = oServer.Text
					  DisplayValidateDeployRoot
					  exit function
				 end if
			next		  
			
		end if	
	next
	
	DisplayValidateDeployRoot

end function


Function DisplayValidateDeployRoot

	 DeployRoot.readonly = RadioCT1.checked
	 if RadioCT1.checked then
		 DeployRoot.style.color = "graytext"
	 else
		 DeployRoot.style.color = ""
	 end if	  
	 
	 SiteList.Disabled = RadioCT2.Checked
		  
	 DisplayValidateDeployRoot = ParseAllWarningLabels
	 
end function 


Function ValidateDeployRoot
	Dim oItem
	Dim oVariable
	Dim oName
	Dim sCmd

	ValidateDeployRoot = DisplayValidateDeployRoot
	 
	If ValidateDeployRoot = FALSE then
		Exit function
	End if


	' Test the share for network access.

	ValidateDeployRoot = FALSE
	 
	Do 
		On Error Resume Next
		Err.Clear
		If oFSO.FileExists(DeployRoot.value & "\Control\OperatingSystems.xml" ) then
			ValidateDeployRoot = TRUE
			Exit Do
		End if
		On Error Goto 0

		If Mid(DeployRoot.value, 2, 2) = ":\" then
			Alert "Invalid or unrecognized path specified!"  ' For example, if they specified W:\Deploy and that didn't exist
			ValidateDeployRoot = FALSE
			Exit Function
		ElseIf not ValidateDeployRoot then

			' Get the credentials and connect to the share!
		  
			oEnvironment.Item("UserID") = ""
			oEnvironment.Item("UserDomain") = ""
			oEnvironment.Item("UserPassword") = ""

			oShell.Run "mshta.exe " & window.document.location.href & " /NotWizard /LeaveShareOpen /ValidateAgainstUNCPath:" & DeployRoot.value & " Credentials_ENU.xml", 1, true
	 	
			If UCase(oEnvironment.Item("UserCredentials")) <> "TRUE" then
				Alert "Could not validate Credentials!"
				Exit function 
			End if

		End if
		 
	Loop until ValidateDeployRoot = TRUE 
	

	' Flush the value to variables.dat, before we continue.

	SaveAllDataElements
	SaveProperties
 
	' Process full rules

	sCmd = "wscript.exe """ & oUtility.ScriptDir & "\ZTIGather.wsf"""
	oItem = oSHell.Run(sCmd, , true)

	' Extract out other fields within the XML Data Object.

	If oXMLSiteData is nothing then
		Exit function
	End if 

	For each oItem in oXMLSiteData.selectNodes("//servers/server")	
		If SiteList.value = oItem.selectSingleNode("serverid").text then	
			For each oVariable in oItem.selectNodes("otherparameters/parameter") 
				Set oName = oVariable.Attributes.getQualifiedItem("name","")
				If not oName is Nothing then
					oProperties(oName.Value) = oVariable.Text
				End if
			Next

		End if	
	Next
	
End Function


Dim UserID_isDirty
UserID_isDirty = FALSE

Function ValidateCredentials

	UserID_isDirty = TRUE
	ValidateCredentials = ParseAllWarningLabelsEx(userdomain, username )
	
End Function 

Function ValidateCredentialsEx
	Dim r
	
	ValidateCredentialsEx = ValidateCredentials
	
	InvalidCredentials.style.display = "none"

	If ValidateCredentialsEx and oEnvironment.Item("OSVersion") <> "WinPE" then

			' Check using ADSI (not possible in Windows PE)

			r = CheckCredentials("", username.value, userdomain.value, userpassword.value)
			If r <> TRUE then

				InvalidCredentials.innerText = "* Invalid credentials: " & r
				InvalidCredentials.style.display = "inline"
				ValidateCredentialsEx = false

			End if


	End if 

end function 



Function RmPropIfFound( Prop )

	If oProperties.Exists(Prop) then
		 oProperties.Remove(Prop) 
	End if

End function


Function ValidateDeploymentType

	ValidateDeploymentType = TRUE		  
	 
	If DTRadio2.Checked then
	 
		' UPGRADE
		  
		RmPropIfFound("UserDataLocation")
		  
		RmPropIfFound("ComputerBackupLocation")
	 
	
	End if

End Function 


'''''''''''''''''''''''''''''''''''''
'  Validate ComputerName
'

Function ValidateComputerName

	' Check Warnings
	ParseAllWarningLabels


	If Len(ComputerName.value) > 15 then
		InvalidChar.style.display = "none"
		TooLong.style.display = "inline"
		ValidateComputerName = false
		ButtonNext.disabled = true
	ElseIf IsValidComputerName ( ComputerName.Value ) then
		ValidateComputerName = TRUE
		InvalidChar.style.display = "none"
		TooLong.style.display = "none"
	Else
		InvalidChar.style.display = "inline"
		TooLong.style.display = "none"
		ValidateComputerName = false
		ButtonNext.disabled = true
	End if
	
End function 


'''''''''''''''''''''''''''''''''''''
'  Validate Domain Membership
'

Function ValidateDomainMembership
	Dim IsDomain
	Dim r
	
	InvalidCredentials.style.display = "none"

	IsDomain = JDRadio1.checked
	 
	JoinDomain.disabled = not IsDomain
	UserName.disabled = not IsDomain
	userdomain.disabled = not IsDomain
	Password.disabled = not IsDomain
	
	MachineObjectOU.disabled = not IsDomain
	MachineObjectOUOptionalBtn.disabled = not isDomain
	MachineObjectOUOptional.disabled = not isDomain
	
	Workgroup.disabled = IsDomain
	

	' Check Warnings

	ValidateDomainMembership = ParseAllWarningLabelsEx(userdomain, UserName)


	' Check credentials

	If IsDomain and ValidateDomainMembership and oEnvironment.Item("OSVersion") <> "WinPE" then

		' Only check credentials when the next button is clicked

		If window.event.srcElement is ButtonNext then

			' Check using ADSI (not possible in Windows PE)

			r = CheckCredentials("", UserName.value, userdomain.value, Password.value) 
			If r <> TRUE then

				InvalidCredentials.innerText = "* Invalid credentials: " & r
				InvalidCredentials.style.display = "inline"
				ValidateDomainMembership = false
				
			End if

		End if

	End if

	
	' We need to clean up the keyboard hook

	If ValidateDomainMembership then	
		document.body.onMouseDown = ""
	End if
	
End Function


'''''''''''''''''''''''''''''''''''''
'  Validate UserData Location
'

Function ValidateUserDataLocation

	InvalidPath.style.display = "none"

	UDRadio2.Value = DataPath.Value	 
	AllowLocal.Disabled = not UDRadio1.Checked		  
	document.GetElementByID("DataPath").Disabled = not UDRadio2.Checked
	document.GetElementByID("DataPathBrowse").Disabled = not UDRadio2.Checked

	ValidateUserDataLocation = ParseAllWarningLabels

	If UDRadio2.Checked then
		If UCase(Left(DataPath.Value, 2)) = UCase(Left(oUtility.LocalRootPath, 2)) and Property("DeploymentType") = "REFRESH" then
			InvalidPath.style.display = "inline"
			ValidateUserDataLocation = false
		End if
	End if

End Function


'''''''''''''''''''''''''''''''''''''
'  Validate UserData Location
'

Function ValidateUserDataRestoreLocation

	UDRadio2.Value = StatePath.Value	 

	document.GetElementByID("StatePath").Disabled = not UDRadio2.Checked
	document.GetElementByID("StatePathBrowse").Disabled = not UDRadio2.Checked
	 
	InvalidPath.style.display = "none"
	ValidateUserDataRestoreLocation = TRUE
	If UDRadio2.Checked and StatePath.value <> "" then
	 
		If Left(StatePath.value, 2) = "\\" and len(StatePath.value) > 6 and ubound(split(StatePath.value,"\")) >= 3 then
			oUtility.ValidateConnection StatePath.value
		End if
		  
		If oFSO.FileExists(StatePath.value & "\USMT3.MIG" ) or ( oFSO.FileExists(StatePath.value & "\MIGSTATE.DAT" ) and _
			oFSO.FileExists(StatePath.value & "\catalog.mig" ) ) then

			' Just in case the user selects the USMT3 directory.
			StatePath.value = StatePath.value & "\.."

		End if

		If not oFSO.FolderExists(StatePath.value & "\USMT3" ) then
			ValidateUserDataRestoreLocation = FALSE
			InvalidPath.style.display = "inline"
		Elseif not oFSO.FileExists(StatePath.value & "\USMT3\USMT3.MIG" ) and _
			not oFSO.FileExists(StatePath.value & "\USMT3\MIGSTATE.DAT" ) and _
			not oFSO.FileExists(StatePath.value & "\USMT3\catalog.mig" ) then

			ValidateUserDataRestoreLocation = FALSE
			InvalidPath.style.display = "inline"
		End if	 

	End if 
	 
	ValidateUserDataRestoreLocation = ValidateUserDataRestoreLocation and ParseAllWarningLabels

End Function


'''''''''''''''''''''''''''''''''''''
'  Validate Computer Backup Location
'

Function ValidateComputerBackupLocation
	Dim HasErrors	

	HasErrors = FALSE
	document.GetElementByID("CBRadio2").Value = document.GetElementByID("DataPath").Value	 
	 
	document.GetElementByID("AllowLocal").Disabled = not CBRadio1.Checked
	 
	document.GetElementByID("DataPath").Disabled = not CBRadio2.Checked
	document.GetElementByID("DataPathBrowse").Disabled = not CBRadio2.Checked
	 
	ValidateComputerBackupLocation = ParseAllWarningLabels
	
End Function


'''''''''''''''''''''''''''''''''''''
'  Validate task sequence List
'

Function ValidateTSList

	Dim oNode
	Dim oTaskList

	SaveAllDataElements
	' Based on the selected image, set some other variables

	If Ucase(oEnvironment.Item("SkipDeploymentType")) = "YES" Then

		If Ucase(oEnvironment.Item("DeploymentType")) = "REFRESH" or Ucase(OEnvironment.Item("DeploymentType")) = "UPGRADE" Then
			oEnvironment.Item("tmpDeploymentType") = Ucase(OEnvironment.Item("DeploymentType"))
		End If
	End if


	For each oNode in tasksequences.XMLDocument.documentElement.childNodes
		If oNode.Attributes.getNamedItem("guid").value = ForceAsString(Property("TSGuid")) then
					
			TaskSequenceID.value = oNode.selectSingleNode("ID").text
			Set oTaskList = oUtility.CreateXMLDOMObjectEx( oEnvironment.Item("DeployRoot") & "\Control\" & TaskSequenceID.value & "\TS.XML" ) 	

			If oTaskList.SelectSingleNode("//globalVarList/variable[@name='OSGUID']") is nothing then

				' This Task Sequence does NOT contain an OS, It's either a custom step, or a ClientReplace
				oEnvironment.Item("OSGUID")=""
				
				If oNode.SelectSingleNode("TaskSequenceTemplate").text <> "ClientReplace.xml" and oTaskList.SelectSingleNode("//step[@name='Capture User State']") is nothing then
					oProperties("DeploymentType")="CUSTOM"
				Else
					oProperties("DeploymentType")="REPLACE"  

					RMPropIfFound("ImageIndex")
					RMPropIfFound("ImageSize")
					RMPRopIfFound("ImageFlags")
					RMPropIfFound("ImageBuild")
					RMPropIfFound("InstallFromPath")
					RMPropIfFound("ImageMemory")

					oEnvironment.Item("ImageProcessor")="x86"
				End if

			Elseif oEnvironment.Item("OSVERSION")="WinPE" Then

				oProperties("DeploymentType")="NEWCOMPUTER"
				
			Else
				If Ucase(oEnvironment.Item("SkipDeploymentType")) = "YES" Then
					oProperties("DeploymentType") = oEnvironment.Item("tmpDeploymentType")
				Else
					oProperties("DeploymentType")=""
				End if
				
			End if
						
			oEnvironment.Item("DeployTemplate")=Ucase(Left(oNode.SelectSingleNode("TaskSequenceTemplate").text,Instr(oNode.SelectSingleNode("TaskSequenceTemplate").text,".")-1))
		End if

	
	Next
	
	ButtonNext.Disabled = True


	' Set the related properties

	oUtility.SetTaskSequenceProperties taskSequenceID.value

	If Left(Property("ImageBuild"), 1) < "6" then 
		RMPropIfFound("LanguagePacks") 
		RMPropIfFound("UserLocaleAndLang") 
		RMPropIfFound("KeyboardLocale") 
		RMPropIfFound("UserLocale") 
		RMPropIfFound("UILanguage") 
		RMPropIfFound("BdePin") 
		RMPropIfFound("BdeModeSelect1") 
		RMPropIfFound("BdeModeSelect2") 
		RMPropIfFound("BdeKeyLocation") 
		RMPropIfFound("WaitForEncryption") 
		RMPropIfFound("BdeInstall") 
		RMPropIfFound("OSDBitLockerWaitForEncryption") 
		RMPropIfFound("BdeRecoveryPassword") 
		RMPropIfFound("BdeInstallSuppress") 
	End If

	' Make sure we have a valid OS by checking the InstallFromPath

'	If oEnvironment.Item("InstallFromPath") = "" then
'		Alert "The selected task sequence does not have a valid OS source path so it cannot be installed"
'		ValidateTSList = FALSE
'		Exit function 
'	End if


'	If not oUtility.ValidateConnection(oEnvironment.Item("InstallFromPath")) = Success then
'		Alert "Unable to establish a connection to " & oEnvironment.Item("InstallFromPath") & " for this task sequence so it cannot be used."
'		ValidateTSList = FALSE
'		Exit Function
'	End if

	ValidateTSList = True
	ButtonNext.Disabled = False
	
End Function


'''''''''''''''''''''''''''''''''''''
'  Validate Password
'

Function ValidatePassword

	ValidatePassword = ParseAllWarningLabels
	
	NonMatchPassword.style.display = "none"
	If Password1.Value <> "" then
		If Password1.Value <> Password2.Value then
			ValidatePassword = FALSE
			NonMatchPassword.style.display = "inline"
		End if 
	End if 
	
	ButtonNext.Disabled = not ValidatePassword
	
End Function


'''''''''''''''''''''''''''''''''''''
'  Validate Capture 
'

Function ValidateCaptureLocation

	InvalidCaptureLocation.style.display = "none"
	ButtonNext.Disabled = false
	
	
	 If not CaptureRadio1.Checked then
		Exit Function
	 End if 

	If Left(ComputerBackupLocation.value, 2) = "\\" and len(ComputerBackupLocation.value) > 6 and ubound(split(ComputerBackupLocation.value,"\")) >= 3 then
		

		If not oUtility.ValidateConnection(ComputerBackupLocation.value) = Success then
				InvalidCaptureLocation.style.display = "inline"			
				 ValidateCaptureLocation = FALSE
				   ButtonNext.Disabled = true 	
				Exit Function
		End if	
		
		ValidateCaptureLocation = Success
		 Exit Function			

	End if
	

	InvalidCaptureLocation.style.display = "inline"	
         ValidateCaptureLocation = FALSE
	  ButtonNext.Disabled = true
		

End Function

Function ValidateCapture

	 document.GetElementByID("ComputerBackupLocation").Disabled = not CaptureRadio1.Checked
	 document.GetElementByID("BackupFile").Disabled = not CaptureRadio1.Checked
	 
	 ValidateCapture = ParseAllWarningLabels
	
	  ValidateCaptureLocation	
End Function


'''''''''''''''''''''''''''''''''''''
'  Validate LanguagePack 
'


function LanguagePack_Validation 

	Dim oPackage , oPackageList
	

	' At least one checkbox must be selected.

	LanguagePack_Validation = false
	SelectLangPack.style.display = "inline"	
	
	Set oPackageList = document.getElementsByName("SelectedItem")
	
	If oPackageList is nothing then
		Exit function
	ElseIf oPackageList.Length < 1 then
		Exit function 
	End if
	 
	For each oPackage in oPackageList	 
		If oPackage.Checked then 
			LanguagePack_Validation = TRUE				
			SelectLangPack.style.display = "none"	
			Exit function 
		End if 
	Next		
	 
End function 


''''''''''''''''''''''''''''''''''''''

Function Locale_Validation

	Locale_Validation = TRUE

	LocaleReq.style.display = "none"
	If UserLocaleAndLang.SelectedIndex = -1 then
		LocaleReq.style.display = "inline"
		Locale_Validation = FALSE
	End if 

	KeyBoardReq.style.display = "none"
	If KeyboardLocale.SelectedIndex = -1 then
		KeyBoardReq.style.display = "inline"
		Locale_Validation = FALSE
	End if 
	 
	If Locale_Validation and instr(1,UserLocaleAndLang.Value,",",vbTextCompare) <> 0 then
	 
		UILanguage.Value = mid(UserLocaleAndLang.Value,instr(1,UserLocaleAndLang.Value,",",vbTextCompare)+1)
		UserLocale.Value = mid(UserLocaleAndLang.Value,1,instr(1,UserLocaleAndLang.Value,",",vbTextCompare)-1)
	 
	End if
 
End function


Function ValidateProductKey

	ValidateProductKey = False

	If Left(Property("ImageBuild"), 1) < "6" then

		' Make sure the product key is valid

		If locProductKey.value = "" then
			PKBlank.style.display = "inline"
			PKInvalid.style.display = "none"
		ElseIf IsEmpty(GetProductKey(locProductKey.value)) then
			PKBlank.style.display = "none"
			PKInvalid.style.display = "inline"
		Else
			PKBlank.style.display = "none"
			PKInvalid.style.display = "none"
			ProductKey.value = GetProductKey(locProductKey.value)
			ValidateProductKey = True
		End if
			
	ElseIf PKRadio1.checked then

		locOverrideProductKey.disabled = true
		locProductKey.disabled = true

		OverrideBlank.style.display = "none"
		OverrideInvalid.style.display = "none"
		PKBlank.style.display = "none"
		PKInvalid.style.display = "none"

		ProductKey.value = ""
		OverrideProductKey.value = ""

		ValidateProductKey = True


	ElseIf PKRadio2.checked then

		locOverrideProductKey.disabled = false
		locProductKey.disabled = true

		PKBlank.style.display = "none"
		PKInvalid.style.display = "none"


		' Make sure the MAK key is valid

		If locOverrideProductKey.value = "" then
			OverrideBlank.style.display = "inline"
			OverrideInvalid.style.display = "none"
		ElseIf IsEmpty(GetProductKey(locOverrideProductKey.value)) then
			OverrideBlank.style.display = "none"
			OverrideInvalid.style.display = "inline"
		Else
			OverrideBlank.style.display = "none"
			OverrideInvalid.style.display = "none"
			OverrideProductKey.value = GetProductKey(locOverrideProductKey.value)
			ProductKey.value = ""
			ValidateProductKey = True
		End if

	Else

		locOverrideProductKey.disabled = true
		locProductKey.disabled = false

		OverrideBlank.style.display = "none"
		OverrideInvalid.style.display = "none"


		' Make sure the product key is valid

		If locProductKey.value = "" then
			PKBlank.style.display = "inline"
			PKInvalid.style.display = "none"
		ElseIf IsEmpty(GetProductKey(locProductKey.value)) then
			PKBlank.style.display = "none"
			PKInvalid.style.display = "inline"
		Else
			PKBlank.style.display = "none"
			PKInvalid.style.display = "none"
			ProductKey.value = GetProductKey(locProductKey.value)
			OverrideProductKey.value = ""
			ValidateProductKey = True
		End if

	End if
		
End Function


const PRODUCT_KEY_TEST = "([0-9A-Z]+)?[^0-9A-Z]*([0-9A-Z]{5})[^0-9A-Z]?([0-9A-Z]{5})[^0-9A-Z]?([0-9A-Z]{5})[^0-9A-Z]?([0-9A-Z]{5})[^0-9A-Z]?([0-9A-Z]{5})[^0-9A-Z]*([0-9A-Z]+)?" ' 


Function GetProductKey( pk )

	Dim regEx, match

	Set regEx = New RegExp 
	regEx.Pattern = PRODUCT_KEY_TEST
	regex.IgnoreCase = TRUE

	For each match in regEx.Execute( UCase(pk) ) 
		If IsEmpty(match.SubMatches(0)) and IsEmpty(match.SubMatches(6)) then 
			GetProductKey = ucase( match.SubMatches(1) & "-" & match.SubMatches(2) & "-" & _ 
			match.SubMatches(3) & "-" & match.SubMatches(4) & "-" & match.SubMatches(5) )
		End if
		Exit function
	Next
	
End function 


Function AssignProductKey

	If not IsEmpty(GetProductKey(locProductKey.value)) then
		locProductKey.value = GetProductKey(locProductKey.value)
	End if
	If Left(Property("ImageBuild"), 1) >= "6" then
		If not IsEmpty(GetProductKey(locOverrideProductKey.value)) then
			locOverrideProductKey.value = GetProductKey(locOverrideProductKey.value)
		End if
	End if

End Function


Function ValidateBDE

	Dim regEx


	' Enable and disable

	If BDERadio2.checked then

		' Enable second set of radio buttons

		BdeModeRadio1.disabled = false
		BdeModeRadio2.disabled = false
		BdeModeRadio3.disabled = false
		BdeModeRadio4.disabled = false

		BdePin.disabled = false
		ADButton1.disabled = false
		ADButton2.disabled = false

		WaitForEncryption.disabled = false
	Else

		' Disable second set of radio buttons
		
		BdeModeRadio1.disabled = true
		BdeModeRadio2.disabled = true
		BdeModeRadio3.disabled = true
		BdeModeRadio4.disabled = true


		BdeModeSelect1.disabled = true
		BdeModeSelect2.disabled = true

		BdePin.disabled = true
		
		ADButton1.disabled = true
		ADButton2.disabled = true

		WaitForEncryption.disabled = true
	End if


	' Scan required fields

	ValidateBDE = ParseAllWarningLabels


	' Set BdeInstall based on choices

	If BDERadio1.checked then
		BdeInstall.value = ""
		BdeInstallSuppress.value = "YES"
	ElseIf BDERadio2.checked then
		BdeInstallSuppress.value = "NO"
	
		' Mode/location
		If BdeModeRadio1.checked then
			BdeInstall.value = "TPM"
			BdePin.disabled = true			
		ElseIf BdeModeRadio2.checked then
			BdeInstall.value = "TPMKey"
			BdeKeyLocation.value = BdeModeSelect1.Value
			BdeModeSelect1.disabled = false
			BdeModeSelect2.disabled = true
			BdePin.disabled = true
		ElseIf BdeModeRadio3.checked then
			BdeInstall.value = "Key"
			BdeKeyLocation.value = BdeModeSelect2.Value
			BdeModeSelect1.disabled = true
			BdeModeSelect2.disabled = false
			BdePin.disabled = true	
		Else	
			BdeInstall.value = "TPMPin"
			BdeModeSelect1.disabled = true
			BdeModeSelect2.disabled = true
			BdePin.disabled = false	
		End if
		
		
		If ADButton1.checked Then
			BdeRecoveryPassword.value = "AD"
		Else
			BdeRecoveryPassword.value = ""
		End if
		
		OSDBitLockerWaitForEncryption.value = WaitForEncryption.checked
		
	Else
		BdeInstall.value = ""
		BdeInstallSuppress.value = "YES"
	End if
 
End Function


Function ValidateBDEDetails

	If BDERadio1.checked then

		BdeKeyLocation.value = "REMOVABLEDRIVE"
		If not BdeLocation.value = "" then
			BdeLocation.value = ""
		End if
		If not BdeLocation.disabled then
			BdeLocation.disabled = true
		End if

	ElseIf BDERadio2.checked then

		If BdeLocation.disabled then
			BdeLocation.disabled = false
		End if
		BdeKeyLocation.value = BdeLocation.value

	Else

		BdeKeyLocation.value = ""

	End if
		 
	ValidateBDEDetails = true

End Function
